package com.yellowpage.omc.keyword.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.omc.keyword.data.Keyword;
import com.yellowpage.omc.keyword.dao.KeywordDao;

public class KeywordServiceImpl extends BaseServiceImpl implements KeywordService {
	  private KeywordDao keywordDao;
	
	  public void setKeywordDao(KeywordDao keywordDao) {
		  this.keywordDao = keywordDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public Keyword getKeyword(Long id){
	      return keywordDao.get(id);
	  }
	  
    public List<Keyword> getAllKeyword(){
        return keywordDao.getAll();
    }
    
    public List<Map> queryKeywordByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.KEYWORD_ID , a.SORT_ORDER , a.CREATE_USER , a.CREATE_TIME , a.LAST_UPDATE_USER , a.LAST_UPDATE_TIME , a.NAME , a.TYPE , a.DESCRIPTION , a.STATUS    FROM OMC_KEYWORD a WHERE 1=1 ")
				    			.addCondition(" and KEYWORD_ID = :keywordId ")
							    			.addCondition(" and SORT_ORDER = :sort_order ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    			.addCondition(" and NAME = :name ")
							    			.addCondition(" and TYPE = :type ")
							    			.addCondition(" and DESCRIPTION = :description ")
							    			.addCondition(" and STATUS = :status ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveKeyword(Keyword keyword){
        keywordDao.save(keyword);
    }
    
	  public void updateKeyword(Keyword keyword){
	      keywordDao.update(keyword);
	  }
	  
	  public void delete(List deleteList){
	      keywordDao.remove(deleteList);
	  }
	  
	  
	 
	
}	